<template>
    <div class="default-main ba-table-box">
        <el-alert class="ba-table-alert" v-if="baTable.table.remark" :title="baTable.table.remark" type="info" show-icon />

        <!-- 表格顶部菜单 -->
        <!-- 自定义按钮请使用插槽，甚至公共搜索也可以使用具名插槽渲染，参见文档 -->
        <TableHeader
            :buttons="['refresh', 'add', 'edit', 'delete', 'comSearch','columnDisplay']"
            :quick-search-placeholder="t('Quick search placeholder', { fields: t('poolLogOrder.quick Search Fields') })"
        ></TableHeader>

        <!-- 表格 -->
        <!-- 表格列有多种自定义渲染方式，比如自定义组件、具名插槽等，参见文档 -->
        <!-- 要使用 el-table 组件原有的属性，直接加在 Table 标签上即可 -->
        <Table ref="tableRef"></Table>

    </div>
</template>

<script setup lang="ts">
import { onMounted, provide, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import { baTableApi } from '/@/api/common'
import { defaultOptButtons } from '/@/components/table'
import TableHeader from '/@/components/table/header/index.vue'
import Table from '/@/components/table/index.vue'
import baTableClass from '/@/utils/baTable'

defineOptions({
    name: 'poolLogOrder',
})

const { t } = useI18n()
const tableRef = ref()
const optButtons: OptButton[] = defaultOptButtons(['edit', 'delete'])


interface Props {
    platform_revenue_type:number
    daterange:Array
}
const props = withDefaults(defineProps<Props>(), {
    platform_revenue_type: 0,
    daterange: [],
})



/**
 * baTable 内包含了表格的所有数据且数据具备响应性，然后通过 provide 注入给了后代组件
 */
const baTable = new baTableClass(
    new baTableApi('/admin/dataBoard/platform_revenue_'),
    {
        pk: 'id',
        column: [
            { type: 'selection', align: 'center', operator: false },
            { label: t('poolLog.user_id'),width:70 , prop: 'user_id', align: 'center', operator: 'eq' },
            { label: t('poolLog.user__nickname'),width:130 , prop: 'user.nickname', align: 'center', operatorPlaceholder: t('Fuzzy query'),  operator: 'LIKE' },
            // { label: t('poolLog.shop_id'),width:150 , prop: 'shop_id', align: 'center', operatorPlaceholder: t('Fuzzy query'), operator: 'LIKE' },
            { label: t('poolLog.shop__name'),width:130 , prop: 'shop.name', align: 'center', operatorPlaceholder: t('Fuzzy query'),  operator: 'LIKE' },
            { label: t('poolLog.order__order_no'),width:200 , prop: 'order.order_no', align: 'center', operatorPlaceholder: t('Fuzzy query'),  operator: 'LIKE' },
            // { label: t('poolLog.order__pay_time'),width:160 , prop: 'order.pay_time', align: 'center', operatorPlaceholder: t('Fuzzy query'),  operator: false },
            { label: t('poolLog.ordergoods__name') ,prop: 'ordergoods.name', align: 'center', operatorPlaceholder: t('Fuzzy query'),  operator: 'LIKE' },
            // { label: t('poolLog.ordergoods__sku_name') , prop: 'ordergoods.sku_name', align: 'center', operatorPlaceholder: t('Fuzzy query'),  operator: 'LIKE' },
            // { label: t('poolLog.price'),width:130 , prop: 'price', align: 'center', operator: 'RANGE', sortable: false },
            { label: t('poolLog.total_price'),width:130 , prop: 'total_price', align: 'center', operator: false, sortable: false },
            // { label: t('poolLog.cost_price'),width:150 , prop: 'cost_price', align: 'center', operator: 'RANGE', sortable: false },
            // { label: t('poolLog.total_cost_price'),width:130 , prop: 'total_cost_price', align: 'center', operator: 'RANGE', sortable: false },
            // { label: t('poolLog.num'),width:130 , prop: 'num', align: 'center', operator: 'RANGE', sortable: false },

            { label: t('poolLog.commission_money'),width:150,show:props.platform_revenue_type == 1 ? true : false , prop: 'commission_money', align: 'center', operator: false, sortable: false },
            { label: t('poolLog.commission_send'),width:150 ,show:props.platform_revenue_type == 2 ? true : false , prop: 'commission_send', align: 'center', operator: false, sortable: false },
            { label: t('poolLog.commission_earnings'),width:150 ,show:props.platform_revenue_type == 3 ? true : false , prop: 'commission_earnings', align: 'center', operator: false, sortable: false },


            { label: t('返购池金额'),width:150 ,show:props.platform_revenue_type == 4 || props.platform_revenue_type == 13  ? true : false , prop: 'back_total', align: 'center', operator: false, sortable: false },
            { label: t('持币池金额'),width:150 ,show:props.platform_revenue_type == 5 || props.platform_revenue_type == 14 ? true : false , prop: 'coin_money', align: 'center', operator: false, sortable: false },
            { label: t('十级池金额'),width:150 ,show:props.platform_revenue_type == 6 ? true : false , prop: 'push_send_money', align: 'center', operator: false, sortable: false },
            { label: t('商家十级池金额'),width:150 ,show:props.platform_revenue_type == 7 ? true : false , prop: 'shop_push_send_money', align: 'center', operator: false, sortable: false },


            { label: t('股东池金额'),width:150 ,show:props.platform_revenue_type == 17 || props.platform_revenue_type == 20  ? true : false , prop: 'shareholder_money', align: 'center', operator: false, sortable: false },
            { label: t('十人池金额'),width:150 ,show:props.platform_revenue_type == 18 || props.platform_revenue_type == 22 ? true : false , prop: 'ten_money', align: 'center', operator: false, sortable: false },
            { label: t('百人池金额'),width:150 ,show:props.platform_revenue_type == 19 || props.platform_revenue_type == 24  ? true : false , prop: 'hundred_money', align: 'center', operator: false, sortable: false },

            { label: t('时间'), prop: 'commission_time', align: 'center', render: 'datetime', operator: 'RANGE', sortable: 'custom', width: 160, timeFormat: 'yyyy-mm-dd hh:MM:ss' },
            // { label: t('Operate'), align: 'center', width: 100, render: 'buttons', buttons: optButtons, operator: false },
        ],
        dblClickNotEditColumn: ['all'],
    },
    {
        defaultItems: { user_id: null, ordergoods_id: null, price: 0, total_price: 0, cost_price: 0, total_cost_price: 0, num: 0, coin_num: 0, get_coin_num: 0, back_buy_money: 0, get_back_buy_money: 0, residue_back_buy_money: 0, directly_return_money: 0, get_directly_return_money: 0, commission_than: 0, commission_money: 0, commission_earnings: 0, push_than: 0, push_money: 0, push_send_money: 0, push_user_ids: null, push_back: 0, shop_push_than: 0, shop_push_money: 0, shop_push_send_money: 0, shop_push_back: 0, shop_indirect_than: 0, shop_indirect_money: 0, shop_indirect_send_money: 0, shop_indirect_user_ids: null, shop_indirect_back: 0, coin_than: 0, coin_money: 0, back_than: 0, back_money: 0, back_total: 0, shop_money: 0, status: 0, back_status: '1', coin_status: '1', commission_time: 0 },
    },{
        onTableAction({ event, data }) {
            if (event == 'com-search') {

                baTable.table.filter!.search = baTable.getComSearchData()

                if (props.daterange){
                    baTable.table.filter!.search.push({field:'commission_time',val:props.daterange[0]+'00:00:00,'+props.daterange[1]+'23:59:59',operator:'RANGE',render:'datetime'})
                }
                // 刷新表格
                baTable.onTableHeaderAction('refresh', { event: 'com-search', data: baTable.table.filter!.search })
                throw Error('')
            }
        }
    }
)

provide('baTable', baTable)

onMounted(() => {
    baTable.table.ref = tableRef.value

    baTable.mount()

    baTable.table.filter!.search = baTable.getComSearchData()
    if (props.daterange && props.daterange.length > 0){
        baTable.table.filter!.search.push({field:'commission_time',val:props.daterange[0]+' 00:00:00,'+props.daterange[1]+' 23:59:59',operator:'RANGE',render:'datetime'})
    }

    // 携带参数
    baTable.table.filter.platform_revenue_type = props.platform_revenue_type

    baTable.getIndex()?.then(() => {
        baTable.initSort()
        baTable.dragSort()
    })

})


</script>

<style scoped lang="scss"></style>
